using Chaotic.DataBase.DataAccess;
using Chaotic.DataBase.DBAccessLibrary.DBAccessLibrary;
using Chaotic.DataBase.DBAccessLibrary.Interface;
using Chaotic.DataBase.DBAccessLibrary.Model;

namespace Chaotic.DataBase.OracleAccess;

public class OracleGrammar : DBGrammar, IGrammar, ILocalGrammar
{  
	public OracleGrammar(ConnectionModel? connect)
		: base(connect)
	{
	}

    public string? IsExistChTableSql => "select table_name from user_tables where table_name='T_FIELD_DICTIONARY'";
	 




   

	public string GetPageingSql(string sql, decimal index, decimal count)
	{
		string format = "SELECT tab.* FROM (SELECT {0} ROWNUMBER,t.* FROM (" + Environment.NewLine + "{1}" + Environment.NewLine + ") t) tab  WHERE tab.ROWNUMBER >= " + index + " and tab.ROWNUMBER < " + count;
		return string.Format(format, "rownum", sql);
	}
	 
	public DatabaseType GetConnectionStr(out string connectStr)
	{
		connectStr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={3})(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={0})));User Id={1};Password={2};Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Timeout=60;Connection Lifetime=0;Persist Security Info=true ";
		connectStr = string.Format(connectStr, _connect.DataBase, _connect.UserID, _connect.PassWord, _connect.Server);
		return DatabaseType.Oracle;
	}
}
